package com.mmlc.meimei.lichengkongjian.mine;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.mmlc.inter.InterActivity;
import com.mmlc.inter.ViewPagerFragmentAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.utils.ViewUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/24.
 */
public class SellerTopActivity extends InterActivity {
    @Override
    protected int initContentView() {
        return R.layout.activity_selltop;
    }

    List<RadioButton> radios = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();
    RadioButton rb_mq,rb_store;
    ViewPager vp;
    TextView tv_title;
    ImageView ivBack,ivSet;
    @Override
    protected void initView() {
        tv_title = ViewUtils.getView(activity, R.id.tv_title);
        ivBack = ViewUtils.getView(activity, R.id.iv_back);
        ivSet = ViewUtils.getView(activity, R.id.iv_set);
        tv_title.setText("力诚空间榜");
        ivSet.setVisibility(View.GONE);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        rb_mq = ViewUtils.getView(activity,R.id.rb_mq);
        rb_store = ViewUtils.getView(activity,R.id.rb_store);
        radios.add(rb_mq);
        radios.add(rb_store);
        vp = ViewUtils.getView(activity,R.id.sell_viewPager);
        MqTopFragment mq = new MqTopFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type",0);
        mq.setArguments(bundle);
        fragments.add(mq);
        MqTopFragment store = new MqTopFragment();
        Bundle bd = new Bundle();
        bd.putInt("type",1);
        store.setArguments(bd);
        fragments.add(store);
//        fragments.add(new MqTopFragment());
        vp.setAdapter(new ViewPagerFragmentAdapter(getSupportFragmentManager(), fragments));
    }

    int navIndex = 0;

    @Override
    protected void initEvent() {

        ((RadioGroup) ViewUtils.getView(activity, R.id.rgsell_group)).setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group, int checkedId) {
                        switch (checkedId) {
                            case R.id.rb_mq:
                                navIndex = 0;
                                tv_title.setText("力诚空间榜");
                                break;
                            case R.id.rb_store:
                                navIndex = 1;
                                tv_title.setText("店内榜");
                                break;
                        }
                        vp.setCurrentItem(navIndex, false);
                    }
                }
        );

        vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                navIndex = position;
                radios.get(navIndex).setChecked(true);
                if(position==0) {
                    tv_title.setText("力诚空间榜");
                }else{
                    tv_title.setText("店内榜");
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}
